// Purpose : This page list all expert and show there profile
// Date    : 15 Sep, 2007
// Author  : Vinayak Singh Rathore 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
using System.Text;
using System.IO;

public partial class Community_ExpertBelog : System.Web.UI.Page, ICallbackEventHandler
{
    //char tabchar = ' ';  commented at 131008 to fix warning
    public string sCallBackFunctionInvocation;
    public string ReturnValue;
    public string browsertype = "";
    Manager ObjManager = new Manager(true, "ConnectionString");
    protected localFunction lfunction = new localFunction();
    // public bool IsBlank { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (DoctorSearch1.Message == "NoData")
        {
            //lblMessage.Visible = true;
        }
        // DoctorSearch1.fromPage="ABCDE";
        ClientScriptManager cm = Page.ClientScript;
        sCallBackFunctionInvocation = cm.GetCallbackEventReference(this, "message", "ShowTopics", "context", "OnError", true);

        //Make TopLoginIMG Visible to display horizontal login box
        //Added: 29th Jan
        Master.TopLoginIMG = false;

        Master.titleContent = "Health & Medical Doctor Community - Online Doctors Community, Physicians Community";
        Master.descriptionContent = "Findadoc Health Community | Medical Community - Welcome to Online Doctors community, Physicians community on various health & medical topics, you can share your views on doctors community and with many other exciting features for doctors, physicians in online medical community";
        Master.keywordsContent = "doctors community, online doctors community, physicians community, health community, medical community";
        if (!IsPostBack)
        {
            // FETCH MOST ACTIVE TOPICS
            GetMostActiveTopics();

            //            BindTopicList();
            BindList();

        }
        //Added at 17/06/2008
        //Message();
        HttpBrowserCapabilities bc = Request.Browser;
        browsertype = bc.Browser;
    }
    public bool ShowMessage;
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        try
        {
            //hfIsToShowMessage.Value = DoctorSearch1.isBlank ? "1" : "0";            
             //ShowMessage = DoctorSearch1.isBlank ? true : false;
        }
        catch (Exception)
        {
            //caught exception
        }
    }

    /// <summary>
    /// This function is use for bind datalist
    /// </summary>
    /// <author>Vinayak Singh Rathore</author>
    /// <date>1 Oct, 2007</date>
    public void BindList()
    {
        // instance of manager class
        Manager objManager = new Manager(true, "ConnectionString");
        DataSet ds = new DataSet();
        ds = objManager.ExecuteQuery("GetBlogExpert", "expert");
        if (ds.Tables[0].Rows.Count > 0)
        {
            //dlistExpert.DataSource = ds.Tables[0];
            //dlistExpert.DataBind();

        }
        else
        {
            //lblMessage.Text = "No Expert Blog Exist";
            //dlistExpert.DataSource = ds;
            //dlistExpert.DataBind();
        }
        objManager = null;
    }
    /// <summary>
    /// public string ReturnQuiryString(string Id, string Typeid)
    /// This function return a encrypted string
    /// </summary>
    /// <author>Vinayak Singh Rathore</author>
    /// <date>15 August, 2007</date>
    /// <param name="Id"></param>
    /// <param name="Typeid"></param>
    /// <returns>encripted string</returns>
    public string ReturnQuiryString(string Id, string Typeid)
    {
        // string variable for store encrypted value
        string Identity;
        // instance of Encription class
        Encryption objEncription = new Encryption();
        Identity = Id.ToString();
        Identity += "," + Typeid.ToString();
        return objEncription.QueryStringEncode(Identity);
    }

    protected void dlistTopic_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Go")
        {
            Response.Redirect("Forum.aspx?Id=" + e.CommandArgument);
        }
    }

    // TOPICS CODE ENDS

    protected void Doctor_search1_Load(object sender, EventArgs e)
    {
        //if (DoctorSearch1.isBlank = true)
        //{
        //    lblMessage.Visible = true;
        //}
        //else { lblMessage.Visible = false; }
        //lblMessage.Text = "No data found";
    }

    protected string GetUserDetails(object UserType, object id)
    {
        localFunction obj = new localFunction();
        if (UserType.ToString() == "dentist")
        {
            return obj.GetDentInfoForBlog(id.ToString());
        }
        else if (UserType.ToString() == "doctor")
        {
            return obj.GetDrInfoForBlog(id.ToString());
        }

        return "";
    }

    protected void GetMostActiveTopics()
    {
        DataSet ds;
        SqlParameter[] prm = new SqlParameter[1];
        prm[0] = new SqlParameter("@Alpha", SqlDbType.Char, 1);
        prm[0].Value = "";
        ds = ObjManager.ExecuteQuery("GetTopics", prm, "MostActiveTopics");
        dlMostActive.HeaderTemplate = GetTemplate("ucTopicHeaderTemplate.ascx");
        dlMostActive.ItemTemplate = GetTemplate("ucTopicTemplate.ascx");
        dlMostActive.FooterTemplate = GetTemplate("ucTopicFooterTemplate.ascx");
        dlMostActive.DataSource = ds;
        dlMostActive.DataBind();
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        if (eventArgument.ToString() == "0")
            ReturnValue = "";
        else
        {
            switch (eventArgument.ToString())
            {
                case "1":
                    GetTopicsByAplha("a");
                    break;
                case "2":
                    GetTopicsByAplha("b");
                    break;
                case "3":
                    GetTopicsByAplha("c");
                    break;
                case "4":
                    GetTopicsByAplha("d");
                    break;
                case "5":
                    GetTopicsByAplha("e");
                    break;
                case "6":
                    GetTopicsByAplha("f");
                    break;
                case "7":
                    GetTopicsByAplha("g");
                    break;
                case "8":
                    GetTopicsByAplha("h");
                    break;
                case "9":
                    GetTopicsByAplha("i");
                    break;
                case "10":
                    GetTopicsByAplha("j");
                    break;
                case "11":
                    GetTopicsByAplha("k");
                    break;
                case "12":
                    GetTopicsByAplha("l");
                    break;
                case "13":
                    GetTopicsByAplha("m");
                    break;
                case "14":
                    GetTopicsByAplha("n");
                    break;
                case "15":
                    GetTopicsByAplha("o");
                    break;
                case "16":
                    GetTopicsByAplha("p");
                    break;
                case "17":
                    GetTopicsByAplha("q");
                    break;
                case "18":
                    GetTopicsByAplha("r");
                    break;
                case "19":
                    GetTopicsByAplha("s");
                    break;
                case "20":
                    GetTopicsByAplha("t");
                    break;
                case "21":
                    GetTopicsByAplha("u");
                    break;
                case "22":
                    GetTopicsByAplha("v");
                    break;
                case "23":
                    GetTopicsByAplha("w");
                    break;
                case "24":
                    GetTopicsByAplha("x");
                    break;
                case "25":
                    GetTopicsByAplha("y");
                    break;
                case "26":
                    GetTopicsByAplha("z");
                    break;
                case "27":
                    GetTopicsByAplha("z");
                    break;
                default:
                    break;
            }
        }

    }

    public string GetCallbackResult()
    {
        return ReturnValue;
    }

    protected void GetTopicsByAplha(string alpha)
    {
        SqlParameter[] prm = new SqlParameter[1];
        prm[0] = new SqlParameter("@Alpha", SqlDbType.Char, 1);
        prm[0].Value = alpha;

        DataSet sd = new DataSet();
        sd = ObjManager.ExecuteQuery("GetTopics", prm, "test");

        // DATA LIST
        DataList dgTopics = new DataList();
        dgTopics.ID = "GvTopics";
        dgTopics.RepeatColumns = 4;
        dgTopics.HeaderTemplate = GetTemplate("ucTopicHeaderTemplate.ascx");
        dgTopics.ItemTemplate = GetTemplate("ucTopicTemplate.ascx");
        dgTopics.FooterTemplate = GetTemplate("ucTopicFooterTemplate.ascx");
        dgTopics.DataSource = sd;
        dgTopics.DataBind();

        StringWriter sw = new StringWriter();

        if (sd.Tables[0].Rows.Count > 0)
        {

            HtmlTextWriter htw = new HtmlTextWriter(sw);
            dgTopics.RenderControl(htw);
            ReturnValue = sw.ToString();
        }
        else
        {
            ReturnValue = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><b>No Topics Found</b>";
        }
    }

    protected ITemplate GetTemplate(string templateName)
    {
        // CHECK        
        ITemplate template = Page.LoadTemplate("../includes/" + templateName);
        return template;
    }
    private void Message()
    {
        string goToCode = "";
        goToCode = Session["pageFromOrAction"].ToString();
        switch (goToCode)
        {

            case "connect":
                //lblMessage.Text = "No Record";
                //lblMessage.Visible = true;
                break;
            //case "ratePeer":
            //    Response.Redirect(Session["strHttps"] + "Doctor/doctorContent.aspx");
            //    break;
            //case "RateDoctors":
            //    Response.Redirect(Session["strHttp"] + "patient/patient_rate.aspx?fromPage=RateDoctors");
            //    break;
            //case "drMessage":
            //    Response.Redirect(Session["strHttp"] + "boardsblogs/blogs.aspx");
            //    break;
            //case "advanced":
            //    Response.Redirect(Session["strHttp"] + "SearchDoctors_adv.aspx");
            //    break;
            default:
                //lblMessage.Text = "No Record";
                //lblMessage.Visible = false;

                break;
        }
    }
}
